<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //1.求任意2个数中的最大值
    // function fn(x, y) {
    //   return x > y ? x : y
    // }
    // console.log(fn(1, 2))

    //2.求任意数组中最大值

    // function fn(arr = []) {
    //   let max = arr[0]
    //   for (let i = 0; i < arr.length; i++) {
    //     max = max > arr[i] ? max : arr[i]
    //   }
    //   return max
    // }
    // console.log(fn([1, 2, 3, 4, 5]))

    //3.求任意数组中最小值
    // function fn(arr = []) {
    //   let min = arr[0]
    //   for (let i = 0; i < arr.length; i++) {
    //     if (min > arr[i])
    //       min = arr[i]
    //   }
    //   return min
    // }
    // console.log(fn([1, 2, 3, 4, 5]))


    //4.合并 求最大值和最小值
    function fn(arr = []) {
      let max = arr[0]
      let min = arr[0]
      for (let i = 0; i < arr.length; i++) {
        max = max > arr[i] ? max : arr[i]
        min = min > arr[i] ? arr[i] : min
      }
      return [min, max]
    }
    // console.log(fn([1, 2, 3, 4, 5]))

    let arr2 = []
    for (let i = 1; i <= 5; i++) {
      arr2.push(+prompt())
    }

    console.log(fn(arr2))

  </script>
</body>

</html>